package tree;
//请设计一个函数判断一棵二叉树是否 轴对称
//https://leetcode.cn/leetbook/read/illustration-of-algorithm/7fbpzv/
public class 判断对称二叉树 {
      public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
    class Solution {
        public boolean checkSymmetricTree(TreeNode root) {
            return root == null || recur(root.left, root.right);
        }
        boolean recur(TreeNode L, TreeNode R) {
            if(L == null && R == null) return true;
            if(L == null || R == null || L.val != R.val) return false;
            return recur(L.left, R.right) && recur(L.right, R.left);
        }
    }
    class Solution2 {
        public boolean checkSymmetricTree(TreeNode root) {
            return root == null || recur(root.left, root.right);
        }
        boolean recur(TreeNode L, TreeNode R) {
            return (L==null && R==null) || (L!=null && R!=null) && (L.val == R.val)//注意非空判断的顺序
                    && recur(L.left,R.right) && recur(L.right,R.left);
        }
    }

}
